var _n70;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_kc = _n70 = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
  }
  babel_createClass(_ctor, null, [{
    key: "log",
    value: function log() {
      var _len = arguments.length;
      var e = new Array(_len);
      for (var _key = 0; _key < _len; _key++) {
        e[_key] = arguments[_key];
      }
      e.unshift("====>");
      console.log.apply(window, e);
    }
  }, {
    key: "err",
    value: function err() {
      var _len2 = arguments.length;
      var e = new Array(_len2);
      for (var _key2 = 0; _key2 < _len2; _key2++) {
        e[_key2] = arguments[_key2];
      }
      e.unshift("====>");
      console.error.apply(window, e);
    }
  }, {
    key: "init",
    value: function init() {
      var e = cc.view.getVisibleSize();
      _n70.view_x = e.width / 2;
      _n70.view_y = e.height / 2;
      _n70.view_mag = cc.v2(_n70.view_x, _n70.view_y).mag();
      _n70.log("可视区域", _n70.view_x, _n70.view_y);
      _n70.loadData1(null);
      cc.view.setResizeCallback(_n70.init);
    }
  }, {
    key: "leftPad",
    value: function leftPad(e, t) {
      var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "0";
      var _n71 = t - e.length;
      if (_n71 <= 0) {
        return e;
      }
      for (var _i19 = 0; _i19 < _n71; _i19++) {
        e = a + e;
      }
      return e;
    }
  }, {
    key: "showPassTime",
    value: function showPassTime(e) {
      var t = "" + e % 60;
      var a = "" + Math.floor(e / 60);
      return this.leftPad(a, 2) + ":" + this.leftPad(t, 2);
    }
  }, {
    key: "showPercent",
    value: function showPercent(e) {
      return 100 * e + "%";
    }
  }, {
    key: "posToAngle",
    value: function posToAngle(e, t, a, _n72) {
      return 180 * Math.atan2(_n72 - t, a - e) / Math.PI;
    }
  }, {
    key: "forMap",
    value: function forMap(e, t) {
      var a = Object.keys(e);
      var _n88 = 0;
      for (var _i20 = a.length; _n88 < _i20; _n88++) {
        var _e139 = t(a[_n88], _n88);
        if (undefined !== _e139) {
          return _e139;
        }
      }
      return null;
    }
  }, {
    key: "numFormat",
    value: function numFormat(e, t) {
      var a = [{
        value: 1,
        symbol: ""
      }, {
        value: 1e6,
        symbol: "M"
      }, {
        value: 1e9,
        symbol: "G"
      }, {
        value: 1e12,
        symbol: "T"
      }, {
        value: 1e15,
        symbol: "P"
      }, {
        value: 1e18,
        symbol: "E"
      }];
      var _n74;
      for (_n74 = a.length - 1; _n74 > 0 && !(e >= a[_n74].value); _n74--) {
        ;
      }
      return (e / a[_n74].value).toFixed(t).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, "$1") + a[_n74].symbol;
    }
  }, {
    key: "clone",
    value: function clone(e) {
      if (Array.isArray(e)) {
        var _t86 = [];
        var _a66 = 0;
        for (var _i21 = e.length; _a66 < _i21; _a66++) {
          _t86.push(_n70.clone(e[_a66]));
        }
        return _t86;
      }
      if ("[object Object]" === Object.prototype.toString.call(e)) {
        var _t87 = {};
        for (var _a67 in e) {
          _t87[_a67] = _n70.clone(e[_a67]);
        }
        return _t87;
      }
      return e;
    }
  }, {
    key: "uiLayout",
    value: function uiLayout(e, t, a, i, o) {
      var l = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
      if (!t || !i || i.length !== t.length) {
        return void _n70.err("[ERR]uiLayout的fatherNodeArr或itemDataArr配置错误");
      }
      var r = e.layout;
      for (var _n89 = 0; _n89 < r.length; _n89++) {
        var c = r[_n89];
        var d = i[_n89];
        var h = t[_n89];
        var u = d.length;
        if ("gird" === c.type) {
          var _t88 = c.colCount || u;
          Math.ceil(u / _t88);
          var _n76 = c.minItems || u;
          var _i22 = l ? h.children.length : 0;
          var _r = cc.instantiate($2BundleManager.default.instance.getBundleRes("Prefab", c.itemPrefab));
          var g = c.itemPadding || [0, 0];
          var p = c.padding || [0, 0, 0, 0];
          var f = _r.width / 2 + g[0];
          var m = _r.height / 2 + g[1];
          var y = 0 - _t88 + 1;
          var C = 0;
          var v = 0;
          var b = 0;
          for (var _s20 = 0; _s20 < _n76; _s20++) {
            var _n77 = undefined;
            if (v >= _t88) {
              v = 0;
              b++;
            }
            if (l && _s20 < _i22) {
              v++;
              continue;
            }
            _n77 = cc.instantiate(_r);
            var _g = _s20 < u ? d[_s20] : null;
            a.call(o, _n77, e, _g, c, l);
            _n77.parent = h;
            _n77.x = (y + 2 * v) * f - p[1] + p[3];
            _n77.y = (C + 2 * b) * m * -1 - p[0] + p[2];
            if (c.itemProps) {
              for (var _e140 in c.itemProps) {
                _n77[_e140] = c.itemProps[_e140];
              }
            }
            v++;
          }
          if (l && _i22 > u) {
            for (var _e141 = u; _e141 < _i22; _e141++) {
              h.removeChild(h.children[u]);
            }
          }
        }
      }
    }
  }, {
    key: "randomInt",
    value: function randomInt(e, t) {
      return Math.floor(Math.random() * (t - e + 1) + e);
    }
  }, {
    key: "randomBool",
    value: function randomBool() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : .5;
      return Math.random() < e;
    }
  }, {
    key: "randomPosNeg1",
    value: function randomPosNeg1() {
      if (Math.random() > .5) {
        return 1;
      } else {
        return -1;
      }
    }
  }, {
    key: "shuffle",
    value: function shuffle(e) {
      var t = e.length;
      var a = 0;
      for (; t;) {
        var _ref;
        a = Math.random() * t-- >>> 0;
        _ref = [e[a], e[t]];
        e[t] = _ref[0];
        e[a] = _ref[1];
      }
      return e;
    }
  }, {
    key: "randomChoose",
    value: function randomChoose(e, t) {
      if (!t || 1 === t) {
        return [e[Math.floor(Math.random() * e.length)]];
      }
      var a = e.slice(0);
      if (t > e.length) {
        return a;
      }
      var _n78 = 0;
      var i = 0;
      var s = e.length;
      var o = s - t;
      for (; s-- > o;) {
        _n78 = a[i = Math.floor((s + 1) * Math.random())];
        a[i] = a[s];
        a[s] = _n78;
      }
      return a.slice(o);
    }
  }, {
    key: "randomDraw",
    value: function randomDraw(e) {
      var t = Math.random();
      var a = 0;
      for (var _n90 in e) {
        if (t > a && t < a + e[_n90]) {
          return _n90;
        }
        a += e[_n90];
      }
      return null;
    }
  }, {
    key: "randomPick",
    value: function randomPick(e, t) {
      if (!t || 1 === t) {
        return e.splice(Math.floor(Math.random() * e.length), 1);
      }
      if (t > e.length) {
        return e;
      }
      var a = [];
      for (var _n91 = 0; _n91 < t; _n91++) {
        var _t89 = Math.floor(Math.random() * e.length);
        a.push(e.splice(_t89, 1)[0]);
      }
      return a;
    }
  }, {
    key: "resetTexRect",
    value: function resetTexRect(e) {
      if (!e.spriteFrame) {
        return void _n70.err("[ERR]resetTexRect", e);
      }
      var t = e.spriteFrame.getRect();
      var a = e.spriteFrame.getTexture();
      var i = t.x / a.width;
      var s = t.y / a.height;
      var o = (t.x + t.width) / a.width;
      var l = (t.y + t.height) / a.height;
      var r = new cc.Vec4(i, s, o - i, l - s);
      e.getMaterial(0).setProperty("_TexRect", r);
    }
  }, {
    key: "shake",
    value: function shake(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
      var a = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var _n81 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
      var i = {
        shakeCount: t,
        node: e,
        orgX: e.x,
        orgY: e.y,
        isDone: false,
        doneFn() {},
        done: null,
        tw: null
      };
      i.done = function (e, t) {
        e && (i.doneFn = function () {
          e.call(t || i.node);
        });
        return i;
      };
      i.tw = cc.tween(i.node).repeat(i.shakeCount, cc.tween().to(.05, {
        x: i.orgX + _n81,
        y: i.orgY + a
      }).to(.05, {
        x: i.orgX - _n81,
        y: i.orgY - a
      })).call(function () {
        i.doneFn();
      });
      i.tw.start();
      return i;
    }
  }, {
    key: "resetMsgReciever",
    value: function resetMsgReciever(e, t) {
      _n70.msgMap[e] = t;
    }
  }, {
    key: "delMsgReciever",
    value: function delMsgReciever(e) {
      delete _n70.msgMap[e];
    }
  }, {
    key: "regMsgReciever",
    value: function regMsgReciever(e, t) {
      var a = _n70.msgMap[e];
      if (a) {
        _n70.msgMap[e] = function (e) {
          return !!a(e) && t(e);
        };
      } else {
        _n70.resetMsgReciever(e, t);
      }
    }
  }, {
    key: "sendMsg",
    value: function sendMsg(e, t) {
      var a = _n70.msgMap[e];
      a && a(t);
    }
  }, {
    key: "moveTo",
    value: function moveTo(e, t, a) {
      var _n82 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : .5;
      var i = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : function () {};
      var s = t.sub(cc.v2(e.position));
      var o = s.mag();
      if (0 === o) {
        return void i();
      }
      var l = s.x / o * a;
      var r = s.y / o * a;
      cc.tween(e).to(_n82, {
        x: e.x + l,
        y: e.y + r
      }).call(i).start();
    }
  }, {
    key: "updateMove",
    value: function updateMove(e, t, a) {
      var _n83 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 10;
      var i = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
      var s = arguments.length > 5 ? arguments[5] : undefined;
      if (!e || 0 === _n83) {
        return;
      }
      var o = t.sub(a);
      var l = o.mag();
      if (0 === l) {
        return;
      }
      if (0 !== i) {
        if (o.x >= 0) {
          e.scaleX = i;
        } else {
          e.scaleX = -i;
        }
      }
      var r = o.x / l;
      var c = o.y / l;
      if (!(s && !s(o, l, r, c))) {
        e.x += r * _n83;
        e.y += c * _n83;
      }
    }
  }, {
    key: "twoInt",
    value: function twoInt(e) {
      if (e < 10) {
        return "0" + e;
      } else {
        return e;
      }
    }
  }, {
    key: "todayStr",
    value: function todayStr() {
      var e = new Date();
      return "" + e.getFullYear() + _n70.twoInt(e.getMonth() + 1) + _n70.twoInt(e.getDate());
    }
  }, {
    key: "saveDateBatch",
    value: function saveDateBatch(e) {
      _n70.forMap(e, function (t) {
        _n70.saveObj[t] = e[t];
      });
      var t = window.localStorage;
      t && t.setItem(_n70.gameName, JSON.stringify(_n70.saveObj));
    }
  }, {
    key: "saveData",
    value: function saveData(e, t) {
      var a = window.localStorage;
      _n70.saveObj[e] = t;
      a && a.setItem(_n70.gameName, JSON.stringify(_n70.saveObj));
    }
  }, {
    key: "getData",
    value: function getData(e, t) {
      var a = _n70.saveObj[e];
      if (null == a) {
        return t;
      } else {
        return a;
      }
    }
  }, {
    key: "loadData",
    value: function loadData(e) {
      var t = window.localStorage;
      if (t) {
        var _a68 = t.getItem(_n70.gameName);
        if (_a68) {
          _n70.saveObj = JSON.parse(_a68);
          return _n70.saveObj[e];
        }
      }
      return null;
    }
  }, {
    key: "clearData",
    value: function clearData() {
      var e = window.localStorage;
      e && e.removeItem(_n70.gameName);
    }
  }, {
    key: "loadData1",
    value: function loadData1(e) {
      var t = window.localStorage;
      if (t) {
        var _a69 = t.getItem(_n70.gameName);
        if (_a69) {
          _n70.saveObj = JSON.parse(_a69);
          if (!_n70.saveObj.userId) {
            var _e142 = "" + _n70.randomInt(1e8, 999999999);
            this.saveData1("userId", _e142);
          }
          return _n70.saveObj[e];
        }
        {
          var _e143 = "" + _n70.randomInt(1e8, 999999999);
          this.saveData1("userId", _e143);
        }
      }
      return null;
    }
  }, {
    key: "saveData1",
    value: function saveData1(e, t) {
      var a = window.localStorage;
      if (a) {
        _n70.saveObj[e] = t;
        a.setItem(_n70.gameName, JSON.stringify(_n70.saveObj));
      }
    }
  }, {
    key: "getData1",
    value: function getData1(e, t) {
      var a = _n70.saveObj[e];
      if (null == a) {
        return t;
      } else {
        return a;
      }
    }
  }, {
    key: "clearData1",
    value: function clearData1() {
      var e = window.localStorage;
      e && e.removeItem(_n70.gameName);
    }
  }, {
    key: "jget",
    value: function jget(e, t) {
      t || (t = function t(e) {
        if (e) {
          return _n70.err(e);
        }
      });
      var a = new XMLHttpRequest();
      a.open("GET", e, true);
      a.onload = function () {
        if (200 == a.status) {
          return t(null, a.responseText);
        } else {
          return t("[ERR-jget]:" + a.status);
        }
      };
      a.send();
    }
  }, {
    key: "jpost",
    value: function jpost(e, t, a) {
      a || (a = function a(e) {
        if (e) {
          return _n70.err(e);
        }
      });
      var i = new XMLHttpRequest();
      i.open("POST", e, true);
      i.setRequestHeader("Content-Type", "application/json; charset=utf-8");
      var s = JSON.stringify(t);
      i.send(s);
      i.onload = function () {
        if (200 == i.status) {
          var _t90 = {
            postERR: "" + i.responseText
          };
          try {
            _t90 = JSON.parse(i.responseText);
          } catch (e) {
            _n70.err(e);
            return a(null, {
              code: "1111",
              err: "jsonErr:" + i.responseText
            });
          }
          return a(null, _t90);
        }
        return a(null, {
          code: "" + i.status
        });
      };
    }
  }, {
    key: "encodeUTF8",
    value: function encodeUTF8(e) {
      var t;
      var a;
      var _n84;
      var i = [];
      for (t = 0; t < e.length; t++) {
        if ((a = e.charCodeAt(t)) < 128) {
          i.push(a);
        } else if (a < 2048) {
          i.push(192 + (a >> 6 & 31), 128 + (63 & a));
        } else {
          if ((_n84 = 55296 ^ a) >> 10 == 0) {
            a = (_n84 << 10) + (56320 ^ e.charCodeAt(++t)) + 65536, i.push(240 + (a >> 18 & 7), 128 + (a >> 12 & 63));
          } else {
            i.push(224 + (a >> 12 & 15));
          }
          i.push(128 + (a >> 6 & 63), 128 + (63 & a));
        }
      }
      return i;
    }
  }, {
    key: "s",
    value: function s(e) {
      var t = new Uint8Array(_n70.encodeUTF8(e));
      var a;
      var i;
      var s;
      var o = 16 + (t.length + 8 >>> 6 << 4);
      (e = new Uint8Array(o << 2)).set(new Uint8Array(t.buffer));
      e = new Uint32Array(e.buffer);
      s = new DataView(e.buffer);
      for (a = 0; a < o; a++) {
        e[a] = s.getUint32(a << 2);
      }
      e[t.length >> 2] |= 128 << 24 - 8 * (3 & t.length);
      e[o - 1] = t.length << 3;
      var l = [];
      var r = [function () {
        return h[1] & h[2] | ~h[1] & h[3];
      }, function () {
        return h[1] ^ h[2] ^ h[3];
      }, function () {
        return h[1] & h[2] | h[1] & h[3] | h[2] & h[3];
      }, function () {
        return h[1] ^ h[2] ^ h[3];
      }];
      var c = function c(e, t) {
        return e << t | e >>> 32 - t;
      };
      var d = [1518500249, 1859775393, -1894007588, -899497514];
      var h = [1732584193, -271733879, null, null, -1009589776];
      h[2] = ~h[0];
      h[3] = ~h[1];
      for (a = 0; a < e.length; a += 16) {
        var _t91 = h.slice(0);
        for (i = 0; i < 80; i++) {
          l[i] = i < 16 ? e[a + i] : c(l[i - 3] ^ l[i - 8] ^ l[i - 14] ^ l[i - 16], 1);
          s = c(h[0], 5) + r[i / 20 | 0]() + h[4] + l[i] + d[i / 20 | 0] | 0;
          h[1] = c(h[1], 30);
          h.pop();
          h.unshift(s);
        }
        for (i = 0; i < 5; i++) {
          h[i] = h[i] + _t91[i] | 0;
        }
      }
      s = new DataView(new Uint32Array(h).buffer);
      for (a = 0; a < 5; a++) {
        h[a] = s.getUint32(a << 2);
      }
      return Array.prototype.map.call(new Uint8Array(new Uint32Array(h).buffer), function (e) {
        return (e < 16 ? "0" : "") + e.toString(16);
      }).join("");
    }
  }, {
    key: "b",
    value: function b(e) {
      var t = [];
      for (var _n92 in e) {
        t.push(_n92);
      }
      t = t.sort();
      var a = "";
      for (var _n93 = 0; _n93 < t.length; _n93++) {
        var _i23 = e[t[_n93]];
        "object" == typeof _i23 && (_i23 = this.b(_i23));
        a += t[_n93] + _i23;
      }
      return a;
    }
  }, {
    key: "a",
    value: function a(e, t, _a65) {
      var i = [];
      for (var _n94 in e) {
        if (null !== e[_n94] && undefined !== e[_n94]) {
          i.push(_n94);
        } else {
          delete e[_n94];
        }
      }
      i = i.sort();
      var s = _n70.b(e);
      t && (s += t);
      s += _a65 || "pH0Xhyenu2e1zdUg";
      return _n70.s(s);
    }
  }, {
    key: "jax",
    value: function jax(e, t, a) {
      a || (a = function a(e) {
        if (e) {
          return _n70.err(e);
        }
      });
      var i = new XMLHttpRequest();
      var s = Date.now();
      t.s = _n70.a(t, s);
      i.open("POST", e, true);
      i.setRequestHeader("Content-Type", "application/json; charset=utf-8");
      i.setRequestHeader("ts", "" + s);
      var o = JSON.stringify(t);
      i.send(o);
      i.onload = function () {
        if (200 == i.status) {
          var _t92 = {
            jaxERR: "" + i.responseText
          };
          try {
            _t92 = JSON.parse(i.responseText);
          } catch (e) {
            _n70.err(e);
            return a(null, {
              re: "1111",
              err: "jsonErr:" + i.responseText
            });
          }
          return a(null, _t92);
        }
        return a(null, {
          re: "9" + i.status
        });
      };
    }
  }, {
    key: "htInit",
    value: function htInit(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
      if (!e) {
        return;
      }
      var a = {
        gid: e,
        uid: _n70.getData("user", {}).id || "u" + Date.now(),
        v: _n70.htVer
      };
      _n70.jax(_n70.htHost + "init2", a, function (e, a) {
        if (e || !a) {
          _n70.err("jhtERR", e);
          return t(e || new Error("no re"));
        }
        if (0 !== a.re) {
          _n70.err("jht FAILED!" + JSON.stringify(a));
          return t(new Error("err:" + a.re));
        }
        _n70.log("HT init OK:" + _n70.htVer);
        if (a.uid) {
          var _e144 = _n70.getData("user", {});
          _e144.id = a.uid;
          _n70.saveData("user", _e144);
        }
        a.picType && (_n70.picType = a.picType);
        _n70.iconPre = a.iconPre;
        t(null, a);
      });
    }
  }, {
    key: "htGetBox",
    value: function htGetBox(e) {
      var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
      if (!e) {
        return void _n70.err("htGetBox bid为空!!");
      }
      var a = {
        bid: e
      };
      _n70.jax(_n70.htHost + "getBox", a, function (a, i) {
        if (a) {
          return t(a);
        }
        if (0 !== i.re || !i.arr) {
          return t(new Error("服务配置有误bid:" + e + ",re:" + i.re));
        }
        var s = [];
        var o = {};
        for (var _e145 = 0; _e145 < i.arr.length; _e145++) {
          var _t93 = i.arr[_e145];
          for (var _e146 = 0; _e146 < _t93.length; _e146++) {
            var _a70 = _t93[_e146].split("@");
            var _i24 = "";
            var _l7 = "";
            _a70.length >= 4 && "0" !== _a70[3] && (_i24 = "_" + _a70[3]);
            _a70.length >= 5 && (_l7 = _a70[4]);
            if (!o[_a70[0]]) {
              s.push({
                jumpKey: _a70[1],
                mid: _a70[0],
                iconUrl: _n70.iconPre + _a70[0] + _i24 + "." + _n70.picType,
                txt: _a70[2],
                mark: _l7
              });
              o[_a70[0]] = _a70[0];
            }
          }
        }
        t(null, s);
      });
    }
  }]);
  return _ctor;
}();
def_kc.gameName = "td_qyxxz";
def_kc.saveObj = {};
def_kc.view_x = 0;
def_kc.view_y = 0;
def_kc.view_mag = 0;
def_kc.msgMap = {};
def_kc.htVer = "203";
def_kc.picType = "";
def_kc.iconPre = "";
def_kc.htHost = "https://dk.gametdd.com/htApi/ht_api/";
def_kc = _n70 = cc__decorate([ccp_ccclass], def_kc);
exports.default = def_kc;